// 版权归陈超所有


#include "AbilitySystem/ModMagCalculation/MMC_MaxHealth.h"

#include "AbilitySystem/CC_AttributeSet.h"
#include "Interations/CC_CombatInterface.h"

UMMC_MaxHealth::UMMC_MaxHealth()
{
	VigorDef.AttributeToCapture = UCC_AttributeSet::GetVigorAttribute();	//设置需要计算的属性对象
	VigorDef.AttributeSource = EGameplayEffectAttributeCaptureSource::Target;	//设置拾取对象为GE的应用目标
	VigorDef.bSnapshot = false;		//是否应用快照

	RelevantAttributesToCapture.Add(VigorDef);		//添加到捕获属性数值，只有添加到列表，才会去获取属性值
}

float UMMC_MaxHealth::CalculateBaseMagnitude_Implementation(const FGameplayEffectSpec& Spec) const
{
	/*1. 获取Vigor */
	const FGameplayTagContainer* SourceTags = Spec.CapturedSourceTags.GetAggregatedTags();
	const FGameplayTagContainer* TargetTags = Spec.CapturedTargetTags.GetAggregatedTags();

	FAggregatorEvaluateParameters EvaluateParameters;		//聚合器评估参数
	EvaluateParameters.SourceTags = SourceTags;
	EvaluateParameters.TargetTags = TargetTags;

	float Vigor = 0.f;
	GetCapturedAttributeMagnitude(VigorDef, Spec, EvaluateParameters, Vigor);		//获取捕获属性强度
	Vigor = FMath::Max<float>(Vigor, 0.f);

	/*2. 获取Level */
	ICC_CombatInterface* CombatInterface = Cast<ICC_CombatInterface>(Spec.GetContext().GetSourceObject());
	int32 CharacterLevel = CombatInterface->GetCharacterLevel();

	/*3. 计算公式*/
	return (80.f + Vigor * 2.5f + CharacterLevel * 5.f);
}
